﻿using Microsoft.EntityFrameworkCore;

namespace EFCoreSnowFlakeIdDemo.WebApi.Models
{
    public class OrderDbContext:DbContext
    {
        public OrderDbContext(DbContextOptions<OrderDbContext> options)
           : base(options)
        {

        }

        public DbSet<Order> Orders { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Order>(entity =>
            {
                entity.HasKey(o => o.Id);
                entity.Property(e => e.Id)
                    .ValueGeneratedOnAdd()
                    .HasValueGenerator<SnowflakeIdGenerator>();
            });
        }
    }
}
